package com.blb.socket;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ChatClient {

    public void connect() throws IOException {
        ExecutorService pool = Executors.newFixedThreadPool(2);
        //创建客户端连接
        //获得输出流
        Socket socket = new Socket("192.168.7.90",8888);
        DataInputStream in = new DataInputStream(socket.getInputStream());
        DataOutputStream out = new DataOutputStream(socket.getOutputStream());
        //启动了读写线程
        pool.execute(new ReadTask(in));
        pool.execute(new WriteTask(out));
    }

    public static void main(String[] args) {
        try {
            new ChatClient().connect();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
